﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Runtime.Serialization;
using System.Collections.Generic;

/// <summary>
///page 的摘要说明
/// </summary>
[Serializable]
public class page
{
    private int id;
    private List<table> m_tables;
    private user m_user;

    private string filename;
    private XElement root;

    public int Id
    {
        get
        {
            return id;
        }
        set
        {
            id = value;
        }
    }

    public List<table> Mtables
    {
        get
        {
            return m_tables;
        }
        set
        {
            m_tables = value;
        }
    }

    public table getTableByID(string _id)
    {
        for (int i = 0; i < m_tables.Count; i++)
        {
            if (null == m_tables[i])//有可能是null
            {
                continue;
            }
            if (_id == m_tables[i].Id)
            {
                return m_tables[i];
            }
        }
        return null;
    }

    public user Muser
    {
        get
        {
            return m_user;
        }
        set
        {
            m_user = value;
        }
    }


    public page()
    {

    }

    public page(string dir,string username)
    {
        
        //root = XElement.Load(dir + username.ToString() + "//page.xml");
        //XElement Xe = XElement.Load(dir + username + "//websites.xml");
        //int max = root.Elements("row").Count();
        //m_tables = new List<table>();
        //for (int i = 0; i < max; i++)
        //{
        //    m_tables.Add(new table(root.Elements("table").ElementAt(i).Value));
        //    m_tables[i].Mrows = Xe.Elements("web").Where(one => one.Element("ID").Value == m_tables[i].Id.ToString()).Select(one => new row(one)).ToList();
        //}
        //m_user = new user(dir + username + "//user.xml");
    }

	public page(string filename)
	{
        this.filename = filename;
        root = XElement.Load(filename);

        XElement Xe = XElement.Load(filename.Replace("page.", "websites."));
        int max = root.Elements("row").Count();
        for (int i = 0; i < max; i++)
        {
            //m_tables[i] = new table(root.Elements("table").ElementAt(i).Value);
            //m_tables[i].Mrows = Xe.Elements("web").Where(one => one.Element("ID").Value == m_tables[i].Id.ToString()).Select(one => new web(one)).ToList();
        }
        m_user = new user(filename.Replace("page.", "user."));
	}
}
